<template>
  <div class="login-main">
    <Box class="login-box">
      <p>注&nbsp册</p>
      <InputLine v-model="registerForm.username" class="inputline" placeholder="username"/>
      <InputLine v-model="registerForm.password" class="inputline" type="password" placeholder="password"/>
      <InputLine v-model="registerForm.confirm" class="inputline" type="password" placeholder="confirm"/>
      <div class="bottom">
        <Button @click="Register">注册</Button>
        <Button @click="Login">登录</Button>
      </div>
    </Box>
  </div>
</template>

<script>
export default {
  data () {
    return {
      registerForm: {
        username: '',
        password: '',
        confirm: ''
      }
    }
  },
  methods: {
    Register () {
      if (this.registerForm.password === this.registerForm.confirm) {
        this.$http.post('/api/user/register', {
          name: this.registerForm.username,
          username: this.registerForm.username,
          password: this.registerForm.password
        },
        res => {
          if (res.status === 'ok') {
            this.$router.push({ name: 'Login' })
          }
        })
      }
    },
    Login () {
      this.$router.push({ name: 'Login' })
    }
  }
}
</script>


<style lang="less" scoped>
  .login-box{
    width: 400px;
    margin: 250px auto 0;
    font-size: 30px;
    color: #fff;
    text-align: center;
    p{
      margin: 15px 0;
    }
    .inputline{
      margin-top: 15px
    }
    .bottom{
      width: 200px;
      margin: 20px auto;
      display: flex;
      justify-content: space-between;
    }
  }
</style>

